package com.wuliu.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;

import javax.annotation.Resource;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.wuliu.common.annotation.Log;
import com.wuliu.common.core.controller.BaseController;
import com.wuliu.common.core.domain.AjaxResult;
import com.wuliu.common.enums.BusinessType;
import com.wuliu.system.domain.SysAppletRole;
import com.wuliu.system.service.ISysAppletRoleService;
import com.wuliu.common.utils.poi.ExcelUtil;
import com.wuliu.common.core.page.TableDataInfo;

/**
 * 前端角色信息Controller
 *
 * @author realue
 * @date 2023-10-22
 */
@Api(tags = {"前端角色控制器"})
@RestController
@RequestMapping("/system/approle")
public class SysAppletRoleController extends BaseController {
    @Resource
    private ISysAppletRoleService sysAppletRoleService;

    /**
     * 查询前端角色信息列表
     */
    @ApiOperation(value = "查询")
    @PreAuthorize("@ss.hasPermi('system:approle:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysAppletRole sysAppletRole) {
        sysAppletRole.setSysAccount(getSysAccount());
        startPage();
        List<SysAppletRole> list = sysAppletRoleService.selectSysAppletRoleList(sysAppletRole);
        return getDataTable(list);
    }

    /**
     * 导出前端角色信息列表
     */
    @ApiOperation(value = "导出")
    @PreAuthorize("@ss.hasPermi('system:approle:export')")
    @Log(title = "前端角色信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysAppletRole sysAppletRole) {
        sysAppletRole.setSysAccount(getSysAccount());
        List<SysAppletRole> list = sysAppletRoleService.selectSysAppletRoleList(sysAppletRole);
        ExcelUtil<SysAppletRole> util = new ExcelUtil<SysAppletRole>(SysAppletRole.class);
        util.exportExcel(response, list, "前端角色信息数据");
    }

    /**
     * 获取前端角色信息详细信息
     */
    @ApiOperation(value = "详情")
    @PreAuthorize("@ss.hasPermi('system:approle:query')")
    @GetMapping(value = "/{roleId}")
    public AjaxResult getInfo(@PathVariable("roleId") Long roleId) {
        return success(sysAppletRoleService.selectSysAppletRoleByRoleId(roleId));
    }

    /**
     * 新增前端角色信息
     */
    @ApiOperation(value = "新增")
    @PreAuthorize("@ss.hasPermi('system:approle:add')")
    @Log(title = "前端角色信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody @Validated SysAppletRole sysAppletRole) {
        sysAppletRole.setSysAccount(getSysAccount());
        sysAppletRole.setCreateBy(getUsername());
        return toAjax(sysAppletRoleService.insertSysAppletRole(sysAppletRole));
    }

    /**
     * 修改前端角色信息
     */
    @ApiOperation(value = "编辑")
    @PreAuthorize("@ss.hasPermi('system:approle:edit')")
    @Log(title = "前端角色信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody @Validated SysAppletRole sysAppletRole) {
        sysAppletRole.setUpdateBy(getUsername());
        return toAjax(sysAppletRoleService.updateSysAppletRole(sysAppletRole));
    }

    /**
     * 删除前端角色信息
     */
    @ApiOperation(value = "删除")
    @PreAuthorize("@ss.hasPermi('system:approle:remove')")
    @Log(title = "前端角色信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{roleIds}")
    public AjaxResult remove(@PathVariable Long[] roleIds) {
        return toAjax(sysAppletRoleService.deleteSysAppletRoleByRoleIds(roleIds));
    }
}
